import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: sessionStorage.getItem("token"),
    user: JSON.parse(sessionStorage.getItem("user")),
    avatarBaseUrl:'http://localhost:8080/up/getPhoto/',
    //打包用(一共四个地方,还要一个store,一个chatHome.vue)
    // avatarBaseUrl:"http://8.136.254.73:8081/photo/",

  },
  mutations: {
    // set
    SET_TOKENN: (state, token) => {
      state.token = token
      sessionStorage.setItem("token", token)
    },
    SET_USER: (state, user) => {
      state.user = user
      sessionStorage.setItem("user", JSON.stringify(user))
    },
    REMOVE_INFO : (state) => {
      state.token = ''
      state.user = {}
      sessionStorage.setItem("token", '')
      sessionStorage.setItem("user", JSON.stringify(''))
    },
  },
  getters: {
    getToken(state){
      console.log(state);
      /* state值为 { fruits:[ {id:1,text:"苹果",price:20}, {id:2,text:"梨子",price:15}] }, */
      return state.token

    },
    getAvatarBaseUrl(state){
      return state.avatarBaseUrl;
    },
    getUser(state){
      return state.user
    },
  },
  actions: {
  },
  modules: {
  }
})
